import os
import sys
from localsettings import SECRET_KEY, DATABASES, LOCALPATH, DEBUG, MEDIA_ROOT, STATIC_ROOT, MAP_API_KEY

from pprint import pprint

sys.path.append(os.path.join(LOCALPATH, 'allbuttonspressed'))

TEMPLATE_DEBUG = DEBUG

ADMINS = ()

MANAGERS = ADMINS

TIME_ZONE = 'America/New_York'
LANGUAGE_CODE = 'en-us'
SITE_ID = 1

USE_I18N = True
USE_L10N = True

STATIC_URL = '/static/'
MEDIA_URL = '/media/'
#ADMIN_MEDIA_PREFIX = '/static/admin/'
ADMIN_MEDIA_PREFIX = STATIC_URL + "grappelli/"

STATICFILES_DIRS = (
    os.path.join(LOCALPATH, os.path.join('filebrowser', 'media')),
    os.path.join(LOCALPATH, os.path.join('allbuttonspressed', 'static')),
    os.path.join(LOCALPATH, 'static'),
    os.path.join(os.path.dirname(__file__), 'static'),
)

# for django-mediagenerator
PRODUCTION_MEDIA_URL = '/sitemedia/'
DEV_MEDIA_URL = '/devmedia/'
GLOBAL_MEDIA_DIRS = STATICFILES_DIRS 

GENERATED_MEDIA_DIR = os.path.join(LOCALPATH, '_generated_media')
GENERATED_MEDIA_NAMES_FILE = os.path.join(LOCALPATH, '_generated_media_names.py')

STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
)

TEMPLATE_LOADERS = (
    'django.template.loaders.filesystem.Loader',
    'django.template.loaders.app_directories.Loader',
)

MIDDLEWARE_CLASSES = (
    'autoload.middleware.AutoloadMiddleware',
    'mediagenerator.middleware.MediaMiddleware',
    'django.middleware.common.CommonMiddleware',
    'djangotoolbox.middleware.RedirectMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
#    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
#    'django.contrib.messages.middleware.MessageMiddleware',
    'urlrouter.middleware.URLRouterFallbackMiddleware',
)

URL_ROUTE_HANDLERS = (
    'minicms.urlroutes.PageRoutes',
    'blog.urlroutes.BlogRoutes',
    'blog.urlroutes.BlogPostRoutes',
    'redirects.urlroutes.RedirectRoutes',
)

TEMPLATE_CONTEXT_PROCESSORS = (
    'django.contrib.auth.context_processors.auth',
    'django.core.context_processors.media',
    'django.core.context_processors.request',
    'minicms.context_processors.cms',
    'bookmarks.context_processors.map_key',
)

NON_REDIRECTED_PATHS = ('/admin/',)

ROOT_URLCONF = 'scplsite.urls'

TEMPLATE_DIRS = (
    os.path.join(LOCALPATH, 'templates'),
    os.path.join(os.path.dirname(__file__), 'templates'),
    os.path.join(LOCALPATH, os.path.join('allbuttonspressed', 'templates')),
)

INSTALLED_APPS = (
    'django.contrib.contenttypes',
    'django.contrib.auth',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'reversion',
    'grappelli',
    'filebrowser',
    'django.contrib.admin',
    'django.contrib.admindocs',
    'urlrouter',
    'minicms',
    'blog',
    'redirects',
    'simplesocial',
    'autoload',
    'djangotoolbox',
    'google_analytics',
    'google_cse',
    'disqus',
    'mediagenerator',
#    'permission_backend_nonrel',
    'dbindexer',
    'bookmarks',
    'tinymce',
)

#AUTH_PROFILE_MODULE = 'nourish.UserProfile'
AUTHENTICATION_BACKENDS = (
    'django.contrib.auth.backends.ModelBackend',
#    'socialregistration.auth.FacebookAuth',
#    'permission_backend_nonrel.backends.NonrelPermissionBackend',
)
LOGIN_URL          = '/login/'
LOGIN_REDIRECT_URL = '/admin/'
LOGIN_ERROR_URL    = '/login-error/'


LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'handlers': {
    },
    'loggers': {
        'django.request': {
            'handlers': [],
            'level': 'ERROR',
            'propagate': True,
        },
    }
}

# Activate django-dbindexer if available
try:
    if 'native' not in DATABASES:
        import dbindexer
        DATABASES['native'] = DATABASES['default']
        DATABASES['default'] = {'ENGINE': 'dbindexer', 'TARGET': 'native', 'NAME': DATABASES['native']['NAME']}

except ImportError:
    pass

SITE_NAME = 'SCPL Bookmarks'
SITE_DESCRIPTION = 'Linking the real world to the library website'
SITE_COPYRIGHT = '<a href="http://www.santacruzpl.org/">Santa Cruz Public Libraries</a>'

DISQUS_SHORTNAME = ''
GOOGLE_ANALYTICS_ID = ''
GOOGLE_CUSTOM_SEARCH_ID = ''
TWITTER_USERNAME = ''

MEDIA_BUNDLES = (
    ('main.css',
        'scplsite_basic.sass',
        'scplsite_design.sass',
    ),
)

MEDIA_DEV_MODE = DEBUG

AUTOLOAD_SITECONF = 'dbindexes'

TINYMCE_SPELLCHECKER = True

#TINYMCE_COMPRESSOR = True


GRAPPELLI_ADMIN_TITLE = 'SCPL Bookmarks Admin'

FILEBROWSER_DIRECTORY = 'scpl/'
FILEBROWSER_URL_FILEBROWSER_MEDIA = '/static/filebrowser/'
